
package todolist.logic.parser;

import todolist.entity.PriorityType;
import todolist.personalization.PriorityCustomizer;

/**
 * Parser of Priority information.
 * @author Ivan
 */
public class PriorityParser {
	
	private GenericParser _objGP;
	
	public PriorityParser() {
		_objGP = new GenericParser();
	}

	/**
	 * Tries to parse a String containing Priority information.
	 * Priority Type if found, or null otherwise, returned.
	 */
	public PriorityType parsePriority(String pstrInput) {
		// no-match conditions
		if (pstrInput == null)
			return null;
		pstrInput = pstrInput.trim();
		if (pstrInput.length() == 0)
			return null;
		// parse input
		if (_objGP.findMatch(PriorityCustomizer.getInstance().getInputHighPriority(), pstrInput) != null) // high priority
			return PriorityType.PRIORITY_HIGH;
		if (_objGP.findMatch(PriorityCustomizer.getInstance().getInputMidPriority(), pstrInput) != null) // mid priority
			return PriorityType.PRIORITY_MID;
		if (_objGP.findMatch(PriorityCustomizer.getInstance().getInputLowPriority(), pstrInput) != null) // low priority
			return PriorityType.PRIORITY_LOW;
		return null; // all phrases do not match
	}
	
}
